<template>
	<view class="vehicle">
		<view class="vehicle-bottom">
			<view class="fpseach">
				<!-- <u-search placeholder="搜索收款方、付款方名称" shape="square" :show-action="false" height="90" :animation="false"
					v-model="keyword"></u-search> -->

				<view class="">
					<text>总额：</text> <text>{{fpsjtj.zxf}}</text>
				</view>
				<view class="tjyw">
					<view class="">
						<text style="color:#00CC00;">已开：</text> <text>{{fpsjtj.zyk}}</text>
					</view>
					<view class="">
						<text style="color:red;">未开：</text> <text>{{fpsjtj.zkk}}</text>
					</view>
				</view>
			</view>
			<view class="fapkmsg-main">
				<view class="vehicle-car" style="display: block;margin-top: 20rpx; border-radius: 10rpx;">

					<view class="userfpmsg-clas" @click="addfpsqFun">

						<view class="wdfp">
							<view class="">
								<u-icon name="plus"></u-icon>
							</view>
							<view class="">
								<text style="padding-left: 20rpx;">发票申请</text>
							</view>
						</view>
						<!-- <view class="">
						<u-icon style="" class="iconfont" name="arrow-right"></u-icon>
					</view> -->
					</view>
				</view>


				<view class="vehicle-car" style="display: block;margin-top: 20rpx; border-radius: 10rpx;">

					<view class="userfpmsg-clas" @click="fpjlFun">

						<view class="wdfp">
							<view class="">
								<u-icon name="file-text-fill"></u-icon>
							</view>
							<view class="">
								<text style="padding-left: 20rpx;">发票记录</text>
							</view>
						</view>
						<!-- <view class="">
						<u-icon style="" class="iconfont" name="arrow-right"></u-icon>
					</view> -->
					</view>
				</view>

				<!-- 内容 -->
				<view class="vehicle-content-box" v-if="vehicleArrList.length!=0" v-for="(item,index) of vehicleArrList"
					:key="index">
					<!--  -->
					<!-- @click="fpmsgxqFun(item)" -->
					<view class="vehicle-content-bottom">
						<view class="vehicle-carName-phone" style="display: block;">
							<view class="vehicle-carName-phone tjwylb" style="border-bottom: 2rpx solid #eee;">
								<view class="vehicle-carName">
									<text class="vehicle-phone" style="width:180rpx; color:#00CC00;">{{item.sj}}</text>
								</view>
								<view class="vehicle-carName">
									<text class="vehicle-phone" style="width:80rpx;">总额</text>
									<text style="color:#666666;font-size: 32rpx;">¥ <text style="color:#CCCC00;"> {{item.zxf}}</text></text>
								</view>
							</view>

							<view class="tjwylb">
								<view class="vehicle-carName">
									<view><text class="vehicle-phone" style="width:80rpx;">物料</text></view>
									<view><text style="color:#666666;font-size: 32rpx;">¥{{item.wl}}</text></view>
									
									
								</view>
								<view class="vehicle-carName">
									<view class="">
										<text class="vehicle-phone" style="width:80rpx;">运费</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.yf}}</text>
									</view>
								</view>

							</view>
							<view class="tjwylb">
								<view class="vehicle-carName">
									<view class="">
										<text class="vehicle-phone" style="">额度内总额</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.edn}}</text>
									</view>

								</view>
								<view class="vehicle-carName">
									<view class="">
										<text class="vehicle-phone" style="">额度外总额</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.edw}}</text>
									</view>
								</view>
							</view>
							<view class="tjwylb">
								<view class="vehicle-carName">
									<view><text class="vehicle-phone" style="">额度内已开</text></view>
									<view><text style="color:#666666;font-size: 32rpx;">¥{{item.ykpn}}</text></view>
									
									
								</view>
								<view class="vehicle-carName">
									<view><text class="vehicle-phone" style="">额度内未开</text></view>
									
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.kkpn}}</text>
									</view>
								</view>

							</view>

							<view class="tjwylb">
								<view class="vehicle-carName">
									
									<view class="">
										<text class="vehicle-phone" style="">额度外已开</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.ykpw}}</text>
									</view>
									
									
								</view>
								<view class="vehicle-carName">
									
									<view class="">
										<text class="vehicle-phone" style="">额度外未开</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.kkpw}}</text>
									</view>
									
									
								</view>
							</view>
							<view class="tjwylb">
								<view class="vehicle-carName">
									
									<view class="">
										<text class="vehicle-phone" style="">额度内冲抵</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.cdjen}}</text>
									</view>
								</view>
								<view class="vehicle-carName">
									<view class="">
										<text class="vehicle-phone" style="">额度外冲抵</text>
									</view>
									<view class="">
										<text style="color:#666666;font-size: 32rpx;">¥{{item.cdjew}}</text>
									</view>
								</view>
							</view>

						</view>
					</view>
				</view>
				<!--  -->
				<view class="sendorder-loadmore">
					<u-loadmore v-if="vehicleArrList.length!=0" :status="status" :icon-type="iconType"
						:load-text="loadText" />
				</view>
				<!-- 缺醒页 -->
				<view class="zanWSJ" v-if="vehicleArrList.length==0">
					<image :src="getStaticFilePath('/QXY/noData.png')" alt="">
				</view>
				<u-modal v-model="vehicleLoginShow" :content="vehicleContent" :show-cancel-button="true"
					@confirm="vehicleConfirm"></u-modal>
				<!-- <u-select v-model="carTypeShow" :default-value="carTypeIndex" :list="carTypeList" @confirm="carTypeOnConfirm"> -->
				<!-- </u-select> -->
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				status: 'loading',
				iconType: 'flower',
				loadText: {
					loadmore: '实在没有了',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				countpage: 1,
				page: 1,
				vehicleArrList: [],
				vehicleLoginShow: false,
				vehicleContent: '',
				carID: '', //车辆ID
				SETTB402ID: '',
				keyword: '',
				fpsjtj: {}

			}
		},
		onShow() {
			this.vehicleList();
		},
		// onReachBottom() {
		// 	if (this.page == this.countpage) {
		// 		return this.status = "nomore"
		// 	}
		// 	this.page++
		// 	this.vehicleList()
		// },
		methods: {
			ckfp() {
				uni.navigateTo({
					url: '../userfpkprecord/index'
				})
			},
			addfpmsg() {
				uni.navigateTo({
					url: '../userfpkprecord/index'
				})
			},
			openPDF(pdfUrl) {
				uni.downloadFile({
					url: pdfUrl,
					success: downloadResult => {
						if (downloadResult.statusCode === 200) {
							// 下载成功，打开PDF文件
							const filePath = downloadResult.tempFilePath;
							uni.openDocument({
								showMenu: true,
								filePath: filePath,
								success: openResult => {
									console.log('PDF文件打开成功');
								},
								fail: openError => {
									console.error('打开PDF文件失败:', openError);
								}
							});
						} else {
							console.error('下载PDF文件失败:', downloadResult.statusCode);
						}
					},
					fail: downloadError => {
						console.error('下载PDF文件失败:', downloadError);
					}
				});
			},
			addfpsqFun() {
				uni.navigateTo({
					url: '../userfpsq/index'
				})
			},
			fpjlFun(){
				uni.navigateTo({
					url: '../userfpjl/index'
				})
			},
			fpmsgxqFun(item) {
				// let obj = JSON.stringify(item);
				let objStr = JSON.stringify(item); // 将对象转换为字符串
				uni.navigateTo({
					url: '../userfpmsgxq/index?item=' + encodeURIComponent(objStr)
				})
			},
			// 删除
			vehicleConfirm() {
				uni.request({
					url: this.baseUrl + '/set/settb402/delete',
					method: 'post',
					dataType: 'json',
					data: {
						SETTB402ID: this.SETTB402ID,
						carID: this.carID,
						sign: this.userinfo.sign,
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '删除成功',
								duration: 5000,
								icon: 'none',
							});
							this.page = 1
							this.countpage = 1
							this.vehicleList();
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			prohibit(item) {
				this.vehicleLoginShow = true
				this.SETTB402ID = item.SETTB402ID
				this.carID = item.carID
				this.vehicleContent = '您确定要删除车辆' + item.SETTB402CA00 + '吗？'
			},
			modify(item) {
				let testStr

				if (typeof(item.phonenumber) == 'object') {

					testStr = encodeURIComponent(JSON.stringify(item.phonenumber));
				} else {
					let phoneArr = [{
						phone: ''
					}]
					phoneArr[0].phone = item.phonenumber
					testStr = encodeURIComponent(JSON.stringify(phoneArr));
				}

				uni.navigateTo({
					url: '../vehicleModifyCar/index' +
						`?carNumberIpt=${item.SETTB402CA00}&nameIpt=${item.carname}&phoneIpt=${testStr}&tareIpt=${item.SETTB402CA03}&SETTB402ID=${item.SETTB402ID}&carID=${item.carID}`
				})
			},
			//添加
			addfp() {
				uni.navigateTo({
					url: '../userfpkprecord/index'
				})
			},
			vehicleList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				this.status = "loading"
				if (this.userinfo.sign == 'CUS-1') {
					var ORMTB400ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
					var ORMTB400ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/set/settb410/selectKPData',
					method: 'POST',
					dataType: 'json',
					data: {
						// sign: this.userinfo.sign,
						ORMTB410ID: ORMTB400ID //一二级客户id
						// page: this.page,
						// limit: 10,
					},
					success: (res) => {
						uni.hideLoading();
						console.log(res);

						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.vehicleArrList = []
								this.page = 1
								this.countpage = 1
								return
							}
							this.fpsjtj = res.data.data
							var data = this.fpsjtj.detail || []
							if (this.page > 1) {
								this.vehicleArrList = [...this.vehicleArrList, ...data]
							} else {
								this.vehicleArrList = data
							}
							// this.countpage = Math.ceil(res.data.data.total / 10)
						} else {
							this.vehicleArrList = []
							this.page = 1
							this.countpage = 1
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
					},
					fail: (res) => {
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
						uni.hideLoading();
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
		}
	}
</script>

<style scoped>
	.sendorder-loadmore {
		padding: 20rpx 0 20rpx 0;
	}

	.vehicle .zanWSJ {
		padding-top: 200rpx;
	}

	.vehicle .zanWSJ>image {
		display: block;
		margin: 0 auto;
		height: 360rpx;
		width: 43%;
	}


	.vehicle {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	.vehicle .vehicle-car {
		width: 100%;
		background: rgba(255, 255, 255, 1);
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 35rpx 24rpx;

	}

	.vehicle .vehicle-car-box {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.vehicle .vehicle-stick {
		width: 6rpx;
		height: 29rpx;
		display: inline-block;
		background: linear-gradient(0deg, rgba(57, 163, 216, 1), rgba(35, 199, 217, 1));
		border-radius: 8px;
		margin-right: 16rpx;
		line-height: 29rpx;
		position: relative;
		top: 2rpx;
	}

	.vehicle .vehicle-car-details {
		font-size: 32rpx;
		color: rgba(51, 51, 51, 1);
		height: 29rpx;
		line-height: 29rpx;
		/* height: 0.37rem;
	  line-height: 0.37rem; */
	}

	/* 添加 */
	.vehicle-add {
		height: 44rpx;
		font-size: 28rpx;
		color: rgba(255, 254, 254, 1);
		background: rgba(0, 160, 241, 1);
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.vehicle .icontianjia,
	.vehicle .iconxiugai,
	.vehicle .iconbaocun,
	.vehicle .iconshanchu,
	.vehicle .iconqiyong {
		font-size: 26rpx;
		padding-left: 10rpx;
	}

	.vehicle-add-button {
		padding: 0 10rpx;
	}

	/* 内容 */
	.vehicle-content-box {
		width: 100%;
		background: rgba(255, 255, 255, 1);
		border-radius: 10rpx;
		margin-top: 16rpx;

	}

	.vehicle .vehicle-content {
		/* margin-top: 8rpx; */
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
	}

	.vehicle .vehicle-carNumber {
		font-size: 30rpx !important;
		font-weight: bold;
	}

	/* .vehicle .vehicle-bottom view:nth-child(3)>view:first-child text:first-child {} */

	.vehicle .vehicle-button-box {
		display: flex;
		justify-content: flex-end;
		padding: 30rpx 0;
	}

	.vehicle-button-margin {
		margin-right: 20rpx;
	}

	.vehicle-content-bottom {
		padding: 0 24rpx;
	}

	.vehicle-carName-phone {
		/* border-bottom: 2rpx solid rgba(230, 230, 230, 1); */
		display: flex;
		justify-content: space-between;
		padding: 18rpx 0;
	}

	.vehicle input {
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 43rpx !important;
		margin-left: 7rpx;
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
		text-align: center;
		border: 2rpx solid rgba(0, 0, 0, .2);
		border-radius: 6rpx;
	}

	.inputBorder {
		border: none !important;
		text-align: left !important;
	}

	.vehicle-input-one {
		width: 166rpx !important;
	}

	.vehicle-input-two {
		width: 190rpx !important;
	}

	.vehicle-phone {
		width: 200rpx;
		display: inline-block;
		font-size: 32rpx;
		color: rgba(153, 153, 153, 1);
	}

	.vehicle-tare {
		padding: 18rpx 0;
	}

	.vehicle-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}

	.userfpmsg-clas {
		display: flex;
		justify-content: space-between;
	}

	.userfpmsg-clas .wdfp {
		display: flex;
	}

	/* 收货地新style */
	.xjshd {
		position: fixed;
		z-index: 999;
		bottom: 0;
		text-align: center;
		width: 100%;
		/* height: 44rpx;
		font-size: 28rpx; */
		color: rgba(255, 254, 254, 1);
		/* display: flex;
		flex-direction: row;
		align-items: center; */
		background: #fff;
		padding: 30rpx 40rpx;
	}

	.shdList {
		border-radius: 20rpx;
		background: #fff;
		margin: 20rpx;
	}

	.xzxhdz {
		background: #FF0000;
		color: #fff;
		font-size: 24rpx;
		/* padding: 2px; */
		margin-right: 10rpx;
		border-radius: 40rpx;
		width: 40rpx;
		height: 40rpx;
		display: inline-block;
		text-align: center;
	}

	.fpseach {
		background-color: #2979ff;
		/* height: 130rpx; */
		padding: 20rpx;
		color: #fff;
		text-align: center;
	}

	.fapkmsg-main {
		padding: 0 20rpx;
	}

	.an-rig-fix {
		display: flex;
		justify-content: flex-end;
	}

	.tjyw {
		display: flex;
		justify-content: space-between;
		padding-top: 40rpx;
		padding-bottom: 20rpx;

	}

	.tjwylb {
		display: flex;
		justify-content: space-between;
		border-bottom: 2rpx solid #eee;
		padding: 20rpx 0;
	}
</style>
